﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace AFT2
{
    enum ENUM_FILE_TYPE
    {
        FILE_TYPE_UNDEF = 0x00,
        FILE_TYPE_REG = 0x01,    ///< Regular file
        FILE_TYPE_DIR = 0x02,    ///< Directory file
        FILE_TYPE_FIFO = 0x03,   ///< Named pipe (fifo) 
        FILE_TYPE_CHR = 0x04,    ///< Character device 
        FILE_TYPE_BLK = 0x05,    ///< Block device 
        FILE_TYPE_LNK = 0x06,    ///< Symbolic link
        FILE_TYPE_SHAD = 0x07,   ///< SOLARIS ONLY 
        FILE_TYPE_SOCK = 0x08,   ///< UNIX domain socket
        FILE_TYPE_WHT = 0x09,    ///< Whiteout
        FILE_TYPE_VIRT = 0x0a   ///< "Virtual File" created by TSK for file system areas
    }

    [Serializable]
    public class FileDataObject
    {
        public FileDataObject(string[] data)
        {
            Name = data[0];
            Type = Convert.ToInt32(data[1]);
            Size = Convert.ToInt64(data[2]);
            CTime = (new DateTime(1970, 1, 1, 0, 0, 0, 0)).AddSeconds(Double.Parse(data[3])).ToString();
            ATime = (new DateTime(1970, 1, 1, 0, 0, 0, 0)).AddSeconds(Double.Parse(data[4])).ToString();
            MTime = (new DateTime(1970, 1, 1, 0, 0, 0, 0)).AddSeconds(Double.Parse(data[5])).ToString();
            Address = Convert.ToInt64(data[6]);
            if ((Convert.ToInt32(data[7]) & 0x01) == 1)
            {
                Alloc = "Allocated";
            }
            else
            {
                Alloc = "Unallocated";
            }
            Permission = data[8];
            TypeDesc = FileDataObject.typeDesc(Type);
        }

        public string Name { get; set; }
        public int Type { get; set; }
        public long Size { get; set; }
        public string CTime { get; set; }
        public string ATime { get; set; }
        public string MTime { get; set; }
        public long Address { get; set; }
        public string Alloc { get; set; }
        public string Permission { get; set; }
        public string TypeDesc { get; set; }

        static string typeDesc(ENUM_FILE_TYPE type)
        {
            switch (type)
            {
                case ENUM_FILE_TYPE.FILE_TYPE_UNDEF: return "Undefined";
                case ENUM_FILE_TYPE.FILE_TYPE_REG: return "Regular File";
                case ENUM_FILE_TYPE.FILE_TYPE_DIR: return "Directory File";
                case ENUM_FILE_TYPE.FILE_TYPE_FIFO: return "Named Pipe";
                case ENUM_FILE_TYPE.FILE_TYPE_CHR: return "Character Device";
                case ENUM_FILE_TYPE.FILE_TYPE_BLK: return "Block Device";
                case ENUM_FILE_TYPE.FILE_TYPE_LNK: return "Symbolic Link";
                case ENUM_FILE_TYPE.FILE_TYPE_SHAD: return "Solaris Only";
                case ENUM_FILE_TYPE.FILE_TYPE_SOCK: return "Domain Socket";
                case ENUM_FILE_TYPE.FILE_TYPE_WHT: return "Whiteout";
                case ENUM_FILE_TYPE.FILE_TYPE_VIRT: return "Virtual File";
            }
            return "Undefined";
        }
        static string typeDesc(int type)
        {
            return FileDataObject.typeDesc((ENUM_FILE_TYPE)type);
        }
    }
}
